using System;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.GraphicsLibraryFramework;

namespace OpenTK.Windowing.Desktop
{
	public class GLFWGraphicsContext : IGLFWGraphicsContext, IGraphicsContext
	{
		private unsafe readonly Window* _windowPtr;

		private int _swapInterval;

		public unsafe IntPtr WindowPtr => (IntPtr)_windowPtr;

		public unsafe bool IsCurrent => GLFW.GetCurrentContext() == _windowPtr;

		public int SwapInterval
		{
			get
			{
				return _swapInterval;
			}
			set
			{
				GLFW.SwapInterval(value);
				_swapInterval = value;
			}
		}

		public unsafe GLFWGraphicsContext(Window* windowPtr)
		{
			_windowPtr = windowPtr;
		}

		public unsafe void SwapBuffers()
		{
			GLFW.SwapBuffers(_windowPtr);
		}

		public unsafe void MakeCurrent()
		{
			GLFW.MakeContextCurrent(_windowPtr);
		}

		public unsafe void MakeNoneCurrent()
		{
			GLFW.MakeContextCurrent(null);
		}
	}
}
